package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @ClassName SwapNodesInPairs
 * @Description TODO
 * @Date 2019/8/6 13:20
 * @Version 1.0
 **/
public class SwapNodesInPairs {

    public ListNode swapPairs(ListNode head) {
        ListNode result = new ListNode(-1); // 用一个额外的ListNode内存来作为头节点，以便操作
        result.next = head;
        int temp = 0;
        while (head != null && head.next != null) {
            temp = head.val;
            head.val = head.next.val;
            head.next.val = temp;
            head = head.next.next;
        }
        return result.next;
    }
}
